//package com.ruoyi.web.controller.system;
//
//import com.graphbuilder.math.func.EFunction;
//import com.ruoyi.common.config.Global;
//import com.ruoyi.common.constant.Constants;
//import com.ruoyi.common.core.controller.BaseController;
//import com.ruoyi.common.utils.DateUtils;
//import com.ruoyi.common.utils.StringUtilTool;
//import com.ruoyi.common.utils.StringUtils;
//import com.ruoyi.common.utils.file.FileUtils;
//import com.ruoyi.framework.util.ShiroUtils;
//import com.ruoyi.generator.util.WordUtils;
//import com.ruoyi.publish.domain.IdAcceptRegister;
//import com.ruoyi.publish.domain.IdIdentsample;
//import com.ruoyi.publish.domain.IdReport;
//import com.ruoyi.publish.domain.words.AcceptDocument;
//import com.ruoyi.publish.domain.words.AssistanceDocument;
//import com.ruoyi.publish.domain.words.RegisterDocument;
//import com.ruoyi.publish.helper.*;
//import com.ruoyi.publish.service.IIdAcceptRegisterService;
//import com.ruoyi.publish.service.IIdExpertService;
//import com.ruoyi.publish.service.IIdIdentsampleService;
//import com.ruoyi.publish.service.IIdReportService;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
//import org.json.simple.JSONObject;
//import org.json.simple.parser.JSONParser;
//import org.json.simple.parser.ParseException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.MediaType;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.*;
//import java.net.URL;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.ruoyi.web.controller.tool.StringUtilTool.numberSupplement;
//
//
///**
//     * build 表单构建
//     *
//     * @author ruoyi
//     */
//    @Controller
//    @RequestMapping("/sys/word")
//    public  class SysWordController extends BaseController
//    {
//
//        @Value("${ruoyi.wordPath}")
//        private  String  wordBaseDirtory;
//
//        @Value("${ruoyi.wordTempletePath}")
//        private  String  wordTempletePath;
//
//        @Value("${ruoyi.intrServerIp}")
//        private  String  intrServerIp;
//
//        private String prefix = "system/word";
//
//
//
//        @Autowired
//        private IIdAcceptRegisterService idAcceptRegisterService;
//
//        @Autowired
//        private IIdIdentsampleService idIdentsampleService;
//
//        @Autowired
//        private IIdExpertService idExpertService;
//
//        @Autowired
//        private IIdReportService iIdReportService;
//
//
//
//
//        //    出版物鉴定受理通知书
//        @GetMapping("/accept/{id}")
//        public String accept(@PathVariable("id") Long id,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("进入accept");
//
//            IdAcceptRegister  idAcceptRegister1=idAcceptRegisterService.selectIdAcceptRegisterById(id);
//            //判断存储 字段ex3 文件名称是否存在 不存在新建，存在查看
//
//            String dirtory="accept";
//
//            Map<String,Object> map=new HashMap<String,Object>();
//            map.put("${code}",idAcceptRegister1.getEx1());
//            map.put("${sendUnit}",idAcceptRegister1.getSendUnit());
//            map.put("${title}",idAcceptRegister1.getTitle());
//            map.put("${documentNum}",idAcceptRegister1.getDocumentNum());
//            map.put("${sendTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getSendDate()));
//            map.put("${acceptTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getAcceptDate()));
//            map.put("${opinion}",StringUtils.isEmpty(idAcceptRegister1.getRemark())?" ":idAcceptRegister1.getRemark());
//
//
//
//            String templateWordFullPath=wordTempletePath+"/accept.docx";
//            String newsWordPath=wordBaseDirtory+"/accept";
//            if (StringUtils.isEmpty(idAcceptRegister1.getEx3())){
////             生成相应文件返回文件名称
//                String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtory);
//                idAcceptRegister1.setEx3(fileName);//ex3
//                idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//            }else{
//                String filePath=wordBaseDirtory+"/accept"+"/"+idAcceptRegister1.getEx3()+".docx";
//                System.out.println("文件地址="+filePath);
//                if (WordUtils.checkWordFile(filePath)){
//
//                }else{
//                    String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtory);
//                    idAcceptRegister1.setEx3(fileName);//ex3
//                    idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                }
//            }
//
//            String filePath=wordBaseDirtory+"/accept/"+idAcceptRegister1.getEx3()+".docx";
//            String fileName=idAcceptRegister1.getEx3()+".docx";
//
//            System.out.println("进入word查看编辑"+fileName);
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory=accept";
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory=accept";
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
////            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//            file.editorConfig.user.name= "出版平台";
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "出版物鉴定登记表"+idAcceptRegister1.getEx1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//
//
//
//
//
//        //    出版物鉴定登记表
//        @GetMapping("/register/{id}")
//        public String register(@PathVariable("id") Long id,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("进入register");
//
//
//            IdAcceptRegister idAcceptRegister1=idAcceptRegisterService.selectIdAcceptRegisterById(id);
//            //判断存储 字段ex4 文件名称是否存在 不存在新建，存在查看
//
////            RegisterDocument entity=new RegisterDocument();
////            entity.setCode(idAcceptRegister1.getEx1());
////            entity.setSendUnit(idAcceptRegister1.getSendUnit());//送检部门
////            entity.setTitle(idAcceptRegister1.getTitle());//标题
////            entity.setDocumentNum(idAcceptRegister1.getDocumentNum());
////            entity.setSendTime(DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getSendDate()));
////            entity.setAccpetTime(DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getAcceptDate()));
////            entity.setOpinion(idAcceptRegister1.getRemark());
//
//            String dirtoty="register";
//
//            Map<String,Object> map=new HashMap<String,Object>();
//            map.put("${code}",idAcceptRegister1.getEx1());
//            map.put("${sendUnit}",idAcceptRegister1.getSendUnit());
////            map.put("${title}",idAcceptRegister1.getTitle());
//            map.put("${documentNum}",idAcceptRegister1.getDocumentNum());
//            map.put("${sendTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getSendDate()));
//            map.put("${acceptTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getAcceptDate()));
//            map.put("${content}",idAcceptRegister1.getIdentContent());
//            map.put("${sampleType}",idAcceptRegister1.getCategory());
//            map.put("${sampleNum}",idAcceptRegister1.getTypes()+"/"+String.valueOf(idAcceptRegister1.getNum()));
//
//            String templateWordFullPath=wordTempletePath+"/register.docx";
//            String newsWordPath=wordBaseDirtory+"/register";
//            if (StringUtils.isEmpty(idAcceptRegister1.getEx4())){
////             生成相应文件返回文件名称
//                String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                idAcceptRegister1.setEx4(fileName);
//                idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//            }else{
//                String filePath=wordBaseDirtory+"/register/"+idAcceptRegister1.getEx4()+".docx";
//                System.out.println("文件地址="+filePath);
//                if (WordUtils.checkWordFile(filePath)){
//
//                }else{
//                    String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                    idAcceptRegister1.setEx4(fileName);
//                    idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                }
//            }
//
//            String filePath=wordBaseDirtory+"/register/"+idAcceptRegister1.getEx4()+".docx";
//            System.out.println(filePath);
//            String fileName=idAcceptRegister1.getEx4()+".docx";
//
//            System.out.println("进入word查看编辑"+fileName);
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory="+dirtoty;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory="+dirtoty;
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
////            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//            file.editorConfig.user.name= "出版平台";
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "出版物鉴定登记表"+idAcceptRegister1.getEx1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//        //    出版物鉴定登记表
//        @GetMapping("/report/{id}")
//        public String report(@PathVariable("id") Long id,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("进入report");
//
//
//            IdReport idReport=iIdReportService.selectIdReportById(id);
//            //判断存储 字段ex3 文件名称是否存在 不存在新建，存在查看
//            IdAcceptRegister  register=idAcceptRegisterService.selectIdAcceptRegisterById(idReport.getRegisterId());
//            if(idReport==null||register==null){
//                return  "/error";
//            }
//
//            String directory="report";
//
//
//
//            Map<String,Object> map=new HashMap<String,Object>();
////            map.put("${year}",DateUtils.parseDateToStr("YYYY", idReport.getCreateTime()));
//            map.put("${yearCode}","〔"+DateUtils.parseDateToStr("YYYY", idReport.getCreateTime())+"〕"+numberSupplement(idReport.getBy1().split("-")[1],4)+"号");
//            map.put("${sendUnit}",register.getSendUnit());
//            map.put("${birefCase}",idReport.getBriefCase());
//            map.put("${documentNum}",register.getDocumentNum());
//            map.put("${identiTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idReport.getCreateTime()));
//            map.put("${content}", StringUtils.isEmpty(idReport.getIdentiContent())?" ":idReport.getIdentiContent());
//            map.put("${copyrightRecord}",StringUtils.isEmpty(idReport.getCopyrightRecord())?" ":"见附件");
//            map.put("${ideentiSituation}",StringUtils.isEmpty(idReport.getIdentiSituation())?" ":idReport.getIdentiSituation());
//            map.put("${apprCon}",StringUtils.isEmpty(idReport.getAppraCon())?" ":idReport.getAppraCon());
//
//            map.put("${dstr}","该社");
//
//
//            System.out.println("鉴定内容"+map.get("${content}"));
//            System.out.println("鉴定内容1"+idReport.getIdentiContent());
//            System.out.println("鉴定内容1"+StringUtils.isEmpty(idReport.getIdentiContent()));
//            System.out.println("鉴定内容2"+StringUtilTool.isNull(idReport.getIdentiContent()));
//            String idSampleas=idReport.getSampleIds();
//
//            String templeteName="reportYes";
//            String sampleNameS=" ";
//            StringBuffer stringBuffer=new StringBuffer();
//            System.out.println(idSampleas);
//            if("正式出版物".equals(idReport.getAppraCon())){
//
//
//                if (StringUtils.isNotEmpty(idSampleas)){
//                    String idSamplesArray[]=idSampleas.split(",");
//                    Long[] nums=new Long [idSamplesArray.length];
//                    for (int i=0;i<idSamplesArray.length;i++){
//                        nums[i]=Long.parseLong(idSamplesArray[i]);
//                    }
//                    List<IdIdentsample> sampleList=idIdentsampleService.selectIdIdentsampleByIds(nums);
//                    List<String> names = sampleList.stream().map(p -> p.getSampleName()).collect(Collectors.toList());
//                    List<String> publishUnits=new ArrayList<String>();
//                    sampleNameS=StringUtils.join(names,"、");
//
//                    for (IdIdentsample sample:sampleList) {
//                        if (StringUtils.isNotEmpty(sample.getPublishingUnit())){
//                            if (!publishUnits.contains(sample.getPublishingUnit())){
//                                publishUnits.add(sample.getPublishingUnit());
//                            }
//                        }
//                    }
//                    String publishUnit=StringUtils.join(publishUnits,"、");
//
//                    System.out.println("publishUnit"+publishUnit);
//
//
//                    map.put("${na}",sampleNameS);
//                    map.put("${naNum}",sampleNameS+"("+register.getDocumentNum()+")");
//                    map.put("${newn}",StringUtils.isEmpty(publishUnit)?"相关单位进一步核查，提请鉴定的"+sampleNameS+"系该社正式出版物。":publishUnit+"进一步核查，提请鉴定的"+sampleNameS+"系该社正式出版物。");
//                    map.put("${publishUnit}",StringUtils.isEmpty(publishUnit)?" ":publishUnit);
//
//                    System.out.println("sampleNameS"+sampleNameS);
//
//                }
//
//
//            }else if ("非法出版物".equals(idReport.getAppraCon())){
//                templeteName="reportNo";
//                IdIdentsample sample=idIdentsampleService.selectIdIdentsampleById(Long.parseLong(idReport.getSampleIds()));
//
//                String letterOrder=sample.getLetterOrder();
//                map.put("${num}",sample.getSampleCode());
//
//                map.put("${letterOrder}","系来函所附清单的序号"+(StringUtils.isEmpty(letterOrder)?" ":letterOrder));
//
//            }else if("其他".equals(idReport.getAppraCon())){
//                templeteName="reportOther";
//
//                if (StringUtils.isNotEmpty(idSampleas)){
//                    String idSamplesArray[]=idSampleas.split(",");
//                    Long[] nums=new Long [idSamplesArray.length];
//                    for (int i=0;i<idSamplesArray.length;i++){
//                        nums[i]=Long.parseLong(idSamplesArray[i]);
//                    }
//                    List<IdIdentsample> sampleList=idIdentsampleService.selectIdIdentsampleByIds(nums);
//                    List<String> publishUnits=new ArrayList<String>();
//
//                    List<String> names = sampleList.stream().map(p -> p.getSampleName()).collect(Collectors.toList());
//                    sampleNameS=StringUtils.join(names,"、");
//
//                    for (IdIdentsample sample:sampleList) {
//                        if (StringUtils.isNotEmpty(sample.getPublishingUnit())){
//                            if (!publishUnits.contains(sample.getPublishingUnit())){
//                                publishUnits.add(sample.getPublishingUnit());
//                            }
//                        }
//                    }
//                    String publishUnit=StringUtils.join(publishUnits,"、")+"进一步核查，            。";
//
//                    System.out.println("publishUnit"+publishUnit);
//                    map.put("${na}",sampleNameS);
//                    map.put("${naNum}",sampleNameS+"("+register.getDocumentNum()+")");
//                    map.put("${newn}",sampleNameS);
//                    map.put("${publishUnit}",StringUtils.isEmpty(publishUnit)?"":publishUnit);
//
//                }
//            }
//
//
//            System.out.println(map.get("${content}"));
//            String templateWordFullPath=wordTempletePath+"/"+templeteName+".docx";
//            String newsWordPath=wordBaseDirtory+"/"+directory;
//
//            if (StringUtils.isEmpty(idReport.getBy2())){
////             生成相应文件返回文件名称
//                String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,templeteName);
//                idReport.setBy2(fileName);
//                iIdReportService.updateIdReport(idReport);
//            }else{
//                String filePath=wordBaseDirtory+"/"+directory+"/"+idReport.getBy2()+".docx";
//                System.out.println("文件地址="+filePath);
//                if (WordUtils.checkWordFile(filePath)){
//
//                }else{
//                    String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,templeteName);
//                    idReport.setBy2(fileName);
//                    iIdReportService.updateIdReport(idReport);
//                }
//            }
//
//            String filePath=wordBaseDirtory+"/"+directory+"/"+idReport.getBy2()+".docx";
//            String fileName=idReport.getBy2()+".docx";
//            System.out.println(filePath);
//            System.out.println("进入word查看编辑"+fileName);
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory="+directory;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory="+directory;
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "出版物鉴定书"+idReport.getBy1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//        //    鉴定签发单
//        @GetMapping("/issue/{id}")
//        public String Issue(@PathVariable("id") Long id,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("进入Issue");
//
//
//            IdReport idReport=iIdReportService.selectIdReportById(id);
//            //判断存储 字段ex3 文件名称是否存在 不存在新建，存在查看
//            IdAcceptRegister  register=idAcceptRegisterService.selectIdAcceptRegisterById(idReport.getRegisterId());
//            if(idReport==null||register==null){
//                return  "/error";
//            }
//
//            String directory="issue";
//
//            String sammples[]=idReport.getSampleIds().split(",");
//            Long ids[]=new Long[sammples.length];
//            for (int i=0;i<sammples.length;i++) {
//                ids[i]=Long.parseLong(sammples[i]);
//            }
//            List<IdIdentsample> samplesList=idIdentsampleService.selectIdIdentsampleByIds(ids);
//            int sampleNum=0;
//
//            //系来函所附清单的序号
//            List<String> letterOrderLists = samplesList.stream().map(p -> p.getLetterOrder()).collect(Collectors.toList());
//            String letterOrders="系来函所附清单的序号"+StringUtils.join(letterOrderLists,"、"); //系来函所附清单的序号
//
//            for (IdIdentsample sample: samplesList) {
//                sampleNum=sampleNum+Integer.parseInt(sample.getSampleNumber());
//
//            }
//
//            String types="";
////            StringBuffer types=new StringBuffer();
//            if (sammples.length!=0){
//
//                List<Long> sampoleids=new ArrayList<Long>();
//                for (String sample:sammples) {
//                    sampoleids.add(Long.parseLong(sample));
//                }
//                Long sampleIds[] = (Long[]) sampoleids.toArray(new Long[sampoleids.size()]);
//                List<IdIdentsample> samplelists=idIdentsampleService.selectIdIdentsampleByIds(sampleIds);
//                List<String>  typenams=new ArrayList<String>();
//                for (IdIdentsample entity: samplelists) {
//                    if (!typenams.contains(entity.getSampleType())){
//                        typenams.add(entity.getSampleType());
//                    }
//                }
//                String typesAll=String.join(",", typenams);
//                types=typesAll;
//            }
//            Map<String,Object> map=new HashMap<String,Object>();
////            map.put("${year}",DateUtils.parseDateToStr("YYYY", idReport.getCreateTime()));
//            map.put("${code}","〔"+DateUtils.parseDateToStr("YYYY", idReport.getCreateTime())+"〕"+idReport.getBy1()+"号");
//            map.put("${sendUnit}",register.getSendUnit());
//            map.put("${documentNum}",register.getDocumentNum());
//            map.put("${content}",StringUtils.isEmpty(idReport.getIdentiContent())?" ":idReport.getIdentiContent());
//            map.put("${sampleType}",StringUtils.isEmpty(types)?" ":types);
//            map.put("${sampleNum}",String.valueOf(sampleNum));
//
//            map.put("${reportCode}","渝新监测鉴〔"+DateUtils.parseDateToStr("YYYY", idReport.getCreateTime())+"〕"+numberSupplement(idReport.getBy1().split("-")[1],4)+"号");
//
//
//            map.put("${apprCon}",idReport.getAppraCon());
//
//            map.put("${letterOrder}",letterOrders);
//
//
//
//
//
////            String templeteName="reportYes";
////            if ("非法出版物".equals(idReport.getAppraCon())){
////                templeteName="reportNo";
////            }
//            String templateWordFullPath=wordTempletePath+"/issue.docx";
//            String newsWordPath=wordBaseDirtory+"/"+directory;
//
//            if (StringUtils.isEmpty(idReport.getIssue())){
////             生成相应文件返回文件名称
//                String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,directory);
//                idReport.setIssue(fileName);
//                iIdReportService.updateIdReport(idReport);
//            }else{
//                String filePath=wordBaseDirtory+"/"+directory+"/"+idReport.getIssue()+".docx";
//                System.out.println("文件地址="+filePath);
//                if (WordUtils.checkWordFile(filePath)){
//
//                }else{
//                    String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,directory);
//                    idReport.setIssue(fileName);
//                    iIdReportService.updateIdReport(idReport);
//                }
//            }
//
//            String filePath=wordBaseDirtory+"/"+directory+"/"+idReport.getIssue()+".docx";
//            String fileName=idReport.getIssue()+".docx";
//            System.out.println(filePath);
//            System.out.println("进入word查看编辑"+fileName);
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory="+directory;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory="+directory;
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "出版物签发单"+idReport.getBy1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//
//
//        //    协查函 有无附件
//        @GetMapping("/assist/{id}")
//        public String assist(@PathVariable("id") Long id,String yesNo,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("进入assist");
//
//
//            IdAcceptRegister idAcceptRegister1=idAcceptRegisterService.selectIdAcceptRegisterById(id);
//
////            if (idAcceptRegister1!=null||idAcceptRegister1.getId()!=null){
////                return  "500";
////            }
//            IdIdentsample sample=new IdIdentsample();
//            sample.setRegisterId(idAcceptRegister1.getId());
//            List<IdIdentsample>  samplesList=idIdentsampleService.selectIdIdentsampleList(sample);
//            String publishUnits=" ";
//            List<String>  units=new ArrayList<String>();
//            if (samplesList.size()!=0){
//                for (IdIdentsample entity: samplesList) {
//                    if(StringUtils.isNotEmpty(entity.getPublishingUnit())&&!units.contains(entity.getPublishingUnit())){
//                        units.add(entity.getPublishingUnit());
//                    }
//                }
//            }
//
//            if (units.size()!=0){
//                publishUnits=String.join("、",units);
//            }
//            String dirtoty="assist";
//
//            Map<String,Object> map=new HashMap<String,Object>();
//            map.put("${yearCode}","〔"+DateUtils.parseDateToStr("YYYY", idAcceptRegister1.getCreateTime())+"〕"+numberSupplement(idAcceptRegister1.getEx1().split("-")[1],4)+"号");
//            map.put("${sendUnit}",idAcceptRegister1.getSendUnit());
////            map.put("${title}",idAcceptRegister1.getTitle());
//            map.put("${acceptTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getAcceptDate()));
//            map.put("${content}",idAcceptRegister1.getIdentContent());
//            map.put("${sampleType}",idAcceptRegister1.getCategory());
//            map.put("${sampleNum}",String.valueOf(idAcceptRegister1.getNum()));
//            map.put("${sampleName}",String.valueOf(idAcceptRegister1.getDocumentNum()));
//            map.put("${publishUnit}",publishUnits);
//
//
//            String templeteName="assist";
//            if("yes".equals(yesNo)){
//                templeteName="assistFile";
//            }
//
//
//            String templateWordFullPath=wordTempletePath+"/"+templeteName+".docx";
//            String newsWordPath=wordBaseDirtory+"/"+dirtoty;
//            String filePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getEx5()+".docx";
//            System.out.println(filePath);
//            String fileName=idAcceptRegister1.getEx5()+".docx";
//
//
//            if(!"yes".equals(yesNo)){
//
//                if (StringUtils.isEmpty(idAcceptRegister1.getEx5())){
////             生成相应文件返回文件名称
//                    String assistfileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                    idAcceptRegister1.setEx5(assistfileName);
//                    idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                }else{
//                    String assistfilePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getEx5()+".docx";
//                    System.out.println("文件地址="+assistfilePath);
//                    if (WordUtils.checkWordFile(assistfilePath)){
//
//                    }else{
//                        String assistfileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                        idAcceptRegister1.setEx5(assistfileName);
//                        idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                    }
//                }
//
//                 filePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getEx5()+".docx";
//                System.out.println(filePath);
//                 fileName=idAcceptRegister1.getEx5()+".docx";
//
//            }else{
//
//                //协查函 有附件
//                if (StringUtils.isEmpty(idAcceptRegister1.getAssistFile())){
////             生成相应文件返回文件名称
//                    String assistFileFileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                    idAcceptRegister1.setAssistFile(assistFileFileName);
//                    idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                }else{
//                    String assistFileFilePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getAssistFile()+".docx";
//                    System.out.println("文件地址="+assistFileFilePath);
//                    if (WordUtils.checkWordFile(assistFileFilePath)){
//
//                    }else{
//                        String assistFileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                        idAcceptRegister1.setAssistFile(assistFileName);
//                        idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                    }
//                }
//
//                filePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getAssistFile()+".docx";
//                System.out.println(filePath);
//                fileName=idAcceptRegister1.getAssistFile()+".docx";
//            }
//
//
//            System.out.println("进入word查看编辑"+fileName);
//
//
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory="+dirtoty;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory="+dirtoty;
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
////            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//
//            file.editorConfig.user.name=ShiroUtils.getLoginName();
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "协查函"+idAcceptRegister1.getEx1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//
//        //    送达登记表
//        @GetMapping("/deliver/{id}")
//        public String deliver(@PathVariable("id") Long id,HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
//        {
//            System.out.println("deliver");
//
//
//            IdAcceptRegister idAcceptRegister1=idAcceptRegisterService.selectIdAcceptRegisterById(id);
//
//
//            String dirtoty="deliver";
//
//            Map<String,Object> map=new HashMap<String,Object>();
//            map.put("${yearCode}","〔"+DateUtils.parseDateToStr("YYYY", idAcceptRegister1.getCreateTime())+"〕"+numberSupplement(idAcceptRegister1.getEx1().split("-")[1],4)+"号");
//            map.put("${sendUnit}",idAcceptRegister1.getSendUnit());
//            map.put("${documentNum}",idAcceptRegister1.getDocumentNum());
//            map.put("${acceptTime}",DateUtils.parseDateToStr("YYYY年MM月dd日",idAcceptRegister1.getAcceptDate()));
//            map.put("${content}",idAcceptRegister1.getIdentContent());
//            map.put("${sampleType}",idAcceptRegister1.getCategory());
//            map.put("${sampleName}",String.valueOf(idAcceptRegister1.getDocumentNum()));
//
//            map.put("${code}",idAcceptRegister1.getEx1());
//
//
//            IdReport idReport=new IdReport();
//            idReport.setRegisterId(id);
//            List<IdReport>  idReports=iIdReportService.selectIdReportList(idReport);
//            List<String>  reports=new ArrayList<String>();
////            for (int i = 0; i < idReports.size(); i++) {
////                if (Integer.parseInt()idReports.get(i).getBy1().split("-")[1])
////            }
//            for (IdReport report:idReports) {
//                reports.add("渝新监测鉴〔"+DateUtils.parseDateToStr("YYYY", report.getCreateTime())+"〕"+numberSupplement(report.getBy1().split("-")[1],4)+"号");
//            }
//
//
//            if (idReports.size()!=0){
//                map.put("${reportCode}",String.join("、",reports));
//                map.put("${sampleNum}",String.valueOf(idReports.size()));
//
//            }else{
//                map.put("${reportCode}"," ");
//                map.put("${sampleNum}","0");
//
//            }
//
//
//            String templeteName="deliver";
//
//
//
//            String templateWordFullPath=wordTempletePath+"/"+templeteName+".docx";
//            String newsWordPath=wordBaseDirtory+"/"+dirtoty;
//            if (StringUtils.isEmpty(idAcceptRegister1.getDeliver())){
////             生成相应文件返回文件名称
//                String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                idAcceptRegister1.setDeliver(fileName);
//                idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//            }else{
//                String filePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getDeliver()+".docx";
//                System.out.println("文件地址="+filePath);
//                if (WordUtils.checkWordFile(filePath)){
//
//                }else{
//                    String fileName=WordUtils.createWord3(templateWordFullPath,newsWordPath,map,dirtoty);
//                    idAcceptRegister1.setDeliver(fileName);
//                    idAcceptRegisterService.updateIdAcceptRegister(idAcceptRegister1);
//                }
//            }
//
//            String filePath=wordBaseDirtory+"/"+dirtoty+"/"+idAcceptRegister1.getDeliver()+".docx";
//            System.out.println(filePath);
//            String fileName=idAcceptRegister1.getDeliver()+".docx";
//
//            System.out.println("进入word查看编辑"+fileName);
//
//            //word在线编辑
//            DocumentManager.Init(request, response);
//
//            FileModel file = new FileModel(fileName);
//            if ("embedded".equals(request.getParameter("mode")))
//                file.InitDesktop();
//            if ("view".equals(request.getParameter("mode")))
//                file.editorConfig.mode = "view";
//
//            if (DocumentManager.TokenEnabled())
//            {
//                file.BuildToken();
//            }
//
//            String serverPath = DocumentManager.GetServerUrl();
//            String storagePath = ConfigManager.GetProperty("storage-folder");
//            String hostAddress = DocumentManager.CurUserHostAddress(null);
//            String newUrl= intrServerIp  + "/sys/word/wordDownload?fileName="+fileName+"&dirtory="+dirtoty;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= intrServerIp  + "/sys/word/callBack?fileName="+fileName+"&dirtory="+dirtoty;
//
//            System.out.println("newUrl"+newUrl);
//            System.out.println("callBackUrl"+callBackUrl);
//
//
////            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//            file.editorConfig.user.id= ShiroUtils.getUserId().toString();
//
//            file.editorConfig.user.name=ShiroUtils.getLoginName();
//
//            file.documentType="docx";
//            file.document.url=newUrl;
//            file.editorConfig.callbackUrl=callBackUrl;
//            mmap.put("file", file);
//            mmap.put("fileName", "送达登记表"+idAcceptRegister1.getEx1());
//            mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//
//            return prefix + "/Review";
//        }
//
//
//
//
//        /**
//        * @Description: word在线编辑查看界面
//        * @Param:
//        * @return:
//        * @Author: 张泽望
//        * @Date: 2020/11/10
//        */
//        @RequiresPermissions("sys:word:view")
//        @GetMapping()
//        public String view(HttpServletRequest request, HttpServletResponse response, ModelMap mmap )
//        {
//            DocumentManager.Init(request, response);
//
//            String fileName = request.getParameter("fileName");
//            System.out.println(fileName);
////            if (fileName!=null&&fileName.indexOf("_")>0&&fileName.split("_")[1]!=null){
//
////                fileName=fileName.split("_")[1]+".docx";
//
//                FileModel file = new FileModel(fileName);
//                if ("embedded".equals(request.getParameter("mode")))
//                    file.InitDesktop();
//                if ("view".equals(request.getParameter("mode")))
//                    file.editorConfig.mode = "view";
//
//                if (DocumentManager.TokenEnabled())
//                {
//                    file.BuildToken();
//                }
//
//
//                String serverPath = DocumentManager.GetServerUrl();
//                String storagePath = ConfigManager.GetProperty("storage-folder");
//                String hostAddress = DocumentManager.CurUserHostAddress(null);
//                String newUrl= serverPath  + "/sys/word/wordDownload?fileName="+fileName;
////                String callBackUrl= serverPath  + "/CallBackServlet?fileName="+fileName;
//            String callBackUrl= serverPath  + "/sys/word/callBack?fileName="+fileName;
//
//
//
//                file.documentType="doc";
//                file.document.url=newUrl;
//                file.editorConfig.callbackUrl=callBackUrl;
//                mmap.put("file", file);
//                mmap.put("fileName", "出版物鉴定受理通知书");
//                mmap.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
//                System.out.println("docserviceApiUrl"+ConfigManager.GetProperty("files.docservice.url.api"));
//                System.out.println("docserviceApiUrl"+ConfigManager.GetProperty("files.docservice.url.api"));
//                System.out.println("Review");
//
//                return prefix + "/Review";
//
////            }
//
////            System.out.println("Error");
////            return prefix + "/Error";
//
//
//
//        }
//
//
////        public  ModelMap  mapPut(){
////
////        }
//
//
//        /**
//         * 本地资源通用下载
//         */
//        @GetMapping("/wordDownload")
//        public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) throws Exception {
//            String fileName = request.getParameter("fileName");
//            System.out.println("数据库资源地址"+fileName);
//
//            String dirtory = request.getParameter("dirtory");
//            System.out.println("文件目录"+dirtory);
//
//            // 本地资源路径
//            String filePath=wordBaseDirtory+"/"+dirtory+"/"+fileName;
//
//            String localPath = Global.getProfile();
//            System.out.println("本地资源路径"+localPath);
//            System.out.println("文件地址"+filePath);
//
//            String downloadName="";
//            if("accept".equals(dirtory)){
//                downloadName="出版物鉴定受理通知书.docx";
//            }else if("register".equals(dirtory)){
//                downloadName="出版物鉴定登记表.doc";
//
//            }else if("report".equals(dirtory)){
//                downloadName="鉴定报告.doc";
//
//            }
//
//
//
//
//            // 数据库资源地址
////            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
////            System.out.println("数据库资源地址"+downloadPath);
////            // 下载名称
////            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
////            System.out.println("下载名称"+downloadName);
////            downloadPath="D:\\onlyofficeWordFile\\jianding\\"+fileName;
////            downloadName="鉴定报表.docx";
//
//            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
//            FileUtils.setAttachmentResponseHeader(response, downloadName);
//            FileUtils.writeBytes(filePath, response.getOutputStream());
//        }
//
//
//    //    文档回调接口
//
//    @RequestMapping("/callBack")
//    @ResponseBody
//    protected Map CallBack(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        Map<String,Object> resultMap=new HashMap<String,Object>();
//
//       PrintWriter writer = null;
//        JSONObject jsonObj=null;
//        System.out.println("===saveeditedfile------------") ;
//        try {
////            writer = response.getWriter();
//            Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
//            String body = scanner.hasNext() ? scanner.next() : "";
//
//            if (body.length()==0){
//                resultMap.put("error",0);
//                return  resultMap;
//            }
//            jsonObj = (JSONObject) new JSONParser().parse(body);
//            System.out.println("===saveeditedfile:" + jsonObj.toJSONString()) ;
//
//            System.out.println("===saveeditedfile:" + jsonObj.get("status")) ;
//	            /*
//	                0 - no document with the key identifier could be found,
//	                1 - document is being edited,
//	                2 - document is ready for saving,
//	                3 - document saving error has occurred,
//	                4 - document is closed with no changes,
//	                6 - document is being edited, but the current document state is saved,
//	                7 - error has occurred while force saving the document.
//	             * */
//            if ((long) jsonObj.get("status") == 2||(long) jsonObj.get("status")==6) {
//                /*
//                 * 当我们关闭编辑窗口后，十秒钟左右onlyoffice会将它存储的我们的编辑后的文件，，此时status = 2，通过request发给我们，我们需要做的就是接收到文件然后回写该文件。
//                 * */
//                /*
//                 * 定义要与文档存储服务保存的编辑文档的链接。当状态值仅等于2或3时，存在链路。
//                 * */
////                String downloadUri = (String) jsonObj.get("url");
////                System.out.println("====文档编辑完成，现在开始保存编辑后的文档，其下载地址为:" + downloadUri);
////                //解析得出文件名
////                //String fileName = downloadUri.substring(downloadUri.lastIndexOf('/')+1);
////                String fileName = request.getParameter("fileName");
////                System.out.println("====下载的文件名:" + fileName);
////
////                String dirtory=request.getParameter("dirtory");
////
////                URL url = new URL(downloadUri);
////                java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
////                InputStream stream = connection.getInputStream();
////                System.out.println(wordBaseDirtory+"\\"+dirtory+"\\"+fileName);
////                File savedFile = new File(wordBaseDirtory+"\\"+dirtory+"\\"+fileName);
////                try (FileOutputStream out = new FileOutputStream(savedFile)) {
////                    int read;
////                    final byte[] bytes = new byte[1024];
////                    while ((read = stream.read(bytes)) != -1) {
////                        out.write(bytes, 0, read);
////                    }
////                    out.flush();
////                }
////                connection.disconnect();
//
//                resultMap.put("在关闭页面后自动保存","在关闭页面后自动保存");
//            }
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        } catch (ParseException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        /*
//         * status = 1，我们给onlyoffice的服务返回{"error":"0"}的信息，这样onlyoffice会认为回调接口是没问题的，这样就可以在线编辑文档了，否则的话会弹出窗口说明
//         * */
//        if((long) jsonObj.get("status") == 7) {
//            System.out.println("====保存失败:");
//            resultMap.put("error",1);
////            writer.write("{\"error\":1}");
//        }else {
////            writer.write("{\"error\":0}");
//            resultMap.put("error",0);
//        }
//
//        return  resultMap;
//        }
//
//    }
